﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "调查问卷 - 填写问卷");
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		dateNow = datetimeAdvice.getCurrentDateString();
		
		studentId = sessionAdvice.getAutherUserID();
		
		questionId = event.getArg("QSN");
		secureTicket = event.getArg("ST");
		
		passArgs = structNew();
		structInsert( passArgs, "QSN", questionId, true );
		
		currentTab = event.getArg("TabID", "labDetail");
		
		
		sql = "	SELECT
					q.qsn_id,q.title,q.describe
				FROM
					t_questionnaire q
				WHERE
					q.qsn_id = :questionId ";
		
		queryObj = new Query(datasource = application.dnsSlave);

		queryObj.addParam(name="questionId", value=questionId, cfsqltype="cf_sql_char");
		
		rs_ques = queryObj.execute(sql=sql).getResult();
		

		sql = "	SELECT
					q.quo_id,q.question,q.measure
				FROM
					t_quota q
				WHERE
					q.qsn_id = :questionId 
				ORDER BY
					q.quo_idx";
		
		queryObj = new Query(datasource = application.dnsSlave);

		queryObj.addParam(name="questionId", value=questionId, cfsqltype="cf_sql_char");
		
		rs_quota = queryObj.execute(sql=sql).getResult();
		
		
		sql = "	SELECT
					v.quo_id,v.answer
				FROM
					t_vote_response v
					INNER JOIN t_quota q ON q.quo_id = v.quo_id
				WHERE
					q.qsn_id = :sheetId 
					AND
					v.stu_id = :studentId ";
		
		queryObj = new Query(datasource = application.dnsSlave);

		queryObj.addParam(name="sheetId", value=questionId, cfsqltype="cf_sql_char");
		queryObj.addParam(name="studentId", value=studentId, cfsqltype="cf_sql_varchar");
		
		rs_resp = queryObj.execute(sql=sql).getResult();
		
		
		savedOpts = structNew();
		
		for(a = 1;a LTE rs_resp.recordCount; a++){
			structInsert( savedOpts, "OPT" & rs_resp['quo_id'][a], rs_resp['answer'][a], true );
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
            <div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">在线调查</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>填写问卷
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="findStudent">
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labDetail">class="active"</cfif> id="labDetail" tabTarget="Detail">问卷详细情况</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
				
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
				
					});
					// -->
					//]]>
				</script>
				
				<div id="Detail" class="tabContent">
					
					<div class="noticeBlock">
						<h3><cfoutput>#stringAdvice.XHTMLSafeFormat( rs_ques.title )#</cfoutput></h3>
						<p><span class="img icon16x16 message"></span><cfoutput>#stringAdvice.XHTMLSafeFormat( rs_ques.describe )#</cfoutput></p>
						<hr/>
					</div>
					
					<div class="noticeBlock">
						<h2>指标体系</h2>
					</div>
					
					<cfset row = 0 />
					<table class="UItable" id="voteSheet">
						<tr class="cellBorder">
							<td align="center" width="20">序</td>
							<td>问题</td>
							<td width="200" align="center">各指标评价情况</td>
						</tr>
                        
                        <cfloop query="rs_quota">
                        
							<cfset row++ />
							<tr class="cellBorder">
								<td align="center"><span class="number"><cfoutput>#row#</cfoutput></span></td>
								<td><cfoutput>#stringAdvice.XHTMLSafeFormat( rs_quota.question )#</cfoutput></td>
								<td class="quota" rowid="<cfoutput>#rs_quota.quo_id#</cfoutput>">
								<cfswitch expression="#rs_quota.measure#">
									<cfcase value="L1">
										<cfset sign = encrypt(rs_quota.quo_id & 'Y', studentId, "PBEWithMD5AndDES", "Hex") />
										<a <cfif structKeyExists(savedOpts, "OPT" & rs_quota.quo_id) and savedOpts["OPT"&rs_quota.quo_id] eq "Y">class="checked"</cfif> opt="Y" href="javascript:postQuota('<cfoutput>#rs_quota.quo_id#</cfoutput>','Y','<cfoutput>#sign#</cfoutput>');">是</a>
										<cfset sign = encrypt(rs_quota.quo_id & 'N', studentId, "PBEWithMD5AndDES", "Hex") />
										<a <cfif structKeyExists(savedOpts, "OPT" & rs_quota.quo_id) and savedOpts["OPT"&rs_quota.quo_id] eq "N">class="checked"</cfif> opt="N" href="javascript:postQuota('<cfoutput>#rs_quota.quo_id#</cfoutput>','N','<cfoutput>#sign#</cfoutput>');">否</a>
									</cfcase>
									<cfcase value="L3">
										<cfset sign = encrypt(rs_quota.quo_id & 'S', studentId, "PBEWithMD5AndDES", "Hex") />
										<a <cfif structKeyExists(savedOpts, "OPT" & rs_quota.quo_id) and savedOpts["OPT"&rs_quota.quo_id] eq "S">class="checked"</cfif> opt="S" href="javascript:postQuota('<cfoutput>#rs_quota.quo_id#</cfoutput>','S','<cfoutput>#sign#</cfoutput>');">满意</a>
										<cfset sign = encrypt(rs_quota.quo_id & 'Y', studentId, "PBEWithMD5AndDES", "Hex") />
										<a <cfif structKeyExists(savedOpts, "OPT" & rs_quota.quo_id) and savedOpts["OPT"&rs_quota.quo_id] eq "Y">class="checked"</cfif> opt="Y" href="javascript:postQuota('<cfoutput>#rs_quota.quo_id#</cfoutput>','Y','<cfoutput>#sign#</cfoutput>');">基本满意</a>
										<cfset sign = encrypt(rs_quota.quo_id & 'N', studentId, "PBEWithMD5AndDES", "Hex") />
										<a <cfif structKeyExists(savedOpts, "OPT" & rs_quota.quo_id) and savedOpts["OPT"&rs_quota.quo_id] eq "N">class="checked"</cfif> opt="N" href="javascript:postQuota('<cfoutput>#rs_quota.quo_id#</cfoutput>','N','<cfoutput>#sign#</cfoutput>');">不满意</a>
									</cfcase>
									<cfcase value="L4">
										<cfset sign = encrypt(rs_quota.quo_id & 'E', studentId, "PBEWithMD5AndDES", "Hex") />
										<a <cfif structKeyExists(savedOpts, "OPT" & rs_quota.quo_id) and savedOpts["OPT"&rs_quota.quo_id] eq "E">class="checked"</cfif> opt="E" href="javascript:postQuota('<cfoutput>#rs_quota.quo_id#</cfoutput>','E','<cfoutput>#sign#</cfoutput>');">优秀</a>
										<cfset sign = encrypt(rs_quota.quo_id & 'G', studentId, "PBEWithMD5AndDES", "Hex") />
										<a <cfif structKeyExists(savedOpts, "OPT" & rs_quota.quo_id) and savedOpts["OPT"&rs_quota.quo_id] eq "G">class="checked"</cfif> opt="G" href="javascript:postQuota('<cfoutput>#rs_quota.quo_id#</cfoutput>','G','<cfoutput>#sign#</cfoutput>');">较好</a>
										<cfset sign = encrypt(rs_quota.quo_id & 'Y', studentId, "PBEWithMD5AndDES", "Hex") />
										<a <cfif structKeyExists(savedOpts, "OPT" & rs_quota.quo_id) and savedOpts["OPT"&rs_quota.quo_id] eq "Y">class="checked"</cfif> opt="Y" href="javascript:postQuota('<cfoutput>#rs_quota.quo_id#</cfoutput>','Y','<cfoutput>#sign#</cfoutput>');">普通</a>
										<cfset sign = encrypt(rs_quota.quo_id & 'N', studentId, "PBEWithMD5AndDES", "Hex") />
										<a <cfif structKeyExists(savedOpts, "OPT" & rs_quota.quo_id) and savedOpts["OPT"&rs_quota.quo_id] eq "N">class="checked"</cfif> opt="N" href="javascript:postQuota('<cfoutput>#rs_quota.quo_id#</cfoutput>','N','<cfoutput>#sign#</cfoutput>');">不好</a>
									</cfcase>
								</cfswitch>
								</td>
							</tr>
						</cfloop>
					</table>
					
					<form id="formSubmit" onSubmit="showBlock()" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('voteResponsePostDo')#</cfoutput>">
							
						<input name="QueID" type="hidden" value="<cfoutput>#questionId#</cfoutput>" />
						
						<div class="lable">
							<input id="postTrigger" disabled="disabled" class="button disabled" type="submit" value="提交问卷" />
						</div>
					</form>
					
					<div id="out"></div>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						
						function showBlock() {
							
							/* 显示阻挡信息 */
							$.blockUI({ 
										message: '正在提交问卷, 请稍后...',
										css: { 
												'width': '16%',
												'left': '42%',
												'border': 'none', 
												'padding': '15px 5px', 
												'backgroundColor': '#f90', 
												'border-radius': '4px', 
												'opacity': .8, 
												'color': '#fff',
												'cursor': null
												},
										overlayCSS: {
												'backgroundColor': '#000', 
												'opacity': .1 ,
												'cursor': null
												}
										}); 
							
						}
						
						function postQuota( quota, opt, hash ) {
							
							/* 显示阻挡信息 */
							$.blockUI({ 
										message: '正在提交问卷...',
										css: { 
												'width': '16%',
												'left': '42%',
												'border': 'none', 
												'padding': '15px 5px', 
												'backgroundColor': '#69c', 
												'border-radius': '4px', 
												'opacity': .8, 
												'color': '#fff',
												'cursor': null
												},
										overlayCSS: {
												'backgroundColor': '#fff', 
												'opacity': .1 ,
												'cursor': null
												}
										}); 
							
							/* 异步提交投票数据 */
							$.post(
									"<cfoutput>#buildURL('apiPostQuota')#</cfoutput>", 
									{
										'QUOTA' : quota,
										'OPT' : opt,
										'ST' : hash,
										'seed': (new Date()).getTime()
									}, 
									function(data) {
										
										//$("#out").html(data);
										
										result = $.parseJSON(data);
										
										if ( result.success ) {
											
											/* 移除选中标记 */
											$("a[opt]", $("td.quota[rowid='" + quota + "']")).removeClass("checked");
											/* 添加对应选中标记 */
											$("a[opt='" + opt + "']", $("td.quota[rowid='" + quota + "']")).addClass("checked");
											
											/* 检查问卷是否完成 */
											var optNeed = <cfoutput>#rs_quota.recordCount#</cfoutput>;
											var optDone = parseInt( result.optDone );
											
											if ( optNeed == optDone ) {
												$("#postTrigger").removeAttr("disabled").removeClass("disabled");
											}
											
											/* 取消阻挡 */
											$.unblockUI();

										}
										else {
											alert(result.reason);
										}
										
									});
							
						}
						
						// -->
						//]]>
					</script>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>